package MyFront.Controller;

import MyFramePro.Domain.Entity.User;
import MyFramePro.Domain.ResponseResult;
import MyFramePro.Enums.AppHttpCodeEnum;
import MyFramePro.Exception.SystemException;
import MyFramePro.Service.Impl.BlogLoginServiceImpl;
import MyFramePro.Utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class BlogLoginController {

    @Autowired
    private BlogLoginServiceImpl blogLoginService;

    @Resource
    private RedisCache redisCache;

    /**
     * 这里是登录的功能
     */
    @PostMapping(value = "/login")
    public ResponseResult login(@RequestBody User user){

        //1.不存在用户名时，给出提示信息
        if(!StringUtils.hasText(user.getUserName())){
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }

        return blogLoginService.login(user);
    }


    /**
     * 这里是退出登录的功能
     */
    @PostMapping(value = "/logout")
    public ResponseResult logout(){

        return blogLoginService.logout();
    }

}
